package com.llb666.e.shop.domain.service;

import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 斌~
 * @date 2022/9/12 下午6:25
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FdfsService {

    private final FastFileStorageClient fastFileStorageClient;

    /**
     * 上传.
     *
     * @param file     文件
     * @param fileName 后缀 jpg jpeg png
     * @return FullPath
     * @throws Exception 异常
     */
    public String upload(MultipartFile file, String fileName) throws Exception {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(),
                file.getSize(), fileName,null);
        return storePath.getFullPath();
    }

}
